/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ares.service.util;

import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 *
 * @author edgar
 */
public class EnviarEmail {

    public EnviarEmail(){
    }
    
    public String EnviarEmail(String from,
                                  String alias_from,
                                  String to,
                                  String asunto,
                                  String texto) throws Exception {

            try{
                Properties props = System.getProperties();
                props.put("mail.smtp.host", from);

                Session session = Session.getDefaultInstance(props, null);
                MimeMessage message = new MimeMessage(session);
                message.setFrom(new InternetAddress(alias_from));
                 
                //message.setRecipient(type, address) 
                message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
             //   message.addRecipient(Message.RecipientType.,new InternetAddress(to));
                message.setSubject(asunto);
                message.setText(texto, "ISO-8859-1","html");
                Transport.send(message);

                System.out.println("ENVIADO A :"+to);
                System.out.println("TEXTO :"+texto);

                return "1";
            }catch(Exception e){
                System.out.println("ERROR AL ENVIAR CORREO "+e.getMessage());
                //e.printStackTrace();
                return "Error - No se pudo enviarCorreo : "+e.getMessage();
            }
	}

}